package com.geek.tag;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

public class CustomResponseHeaderTag extends SimpleTagSupport {
  private String cacheControl;
  private String pragma;
  private Long expires;

  public void setCacheControl(final String cacheControl) {
    this.cacheControl = cacheControl;
  }

  public void setPragma(final String pragma) {
    this.pragma = pragma;
  }

  public void setExpires(final Long expires) {
    this.expires = expires;
  }

  @Override
  public void doTag() throws JspException, IOException {
    final PageContext pageContext = (PageContext) getJspContext();
    final HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
    System.out.println("ComonResponseHeaderTag cacheControl:" + cacheControl + "  pragma:" + pragma + "  expires:" + expires);

    response.setHeader("Cache-Control", cacheControl);
    response.setHeader("Pragma", pragma);
    response.setHeader("Expires", String.valueOf(expires));
    System.out.println("CommonResponseHeaderTag finish");
  }
}
